<?php
/**
* $Id  helper.php  2006-1-9 ����04:15:56
* o2php! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
* @package		package_name package_declaration
* @copyright	Copyright (C) 2006 - 2009 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* @version $Id
*/
/*
 * 模板助手
 * 模板的类型有html,raw,xml,pdf;
 */
class ETplHelper {
	function __construct() {
	}
	function & getTplSet($econtroller, $emodel, $args = array (), $type = 'html', $return = 'All') {
		static $tplSet, $eTplHelper;
		if (!isset ($tplSet))
			$tplSet = array ();
		if (!isset ($eTplHelper))
			$eTplHelper = new eTplHelper();
		if (!empty ($args)) {
			$args = '-' . implode('-', $args);
		} else {
			$args = '';
		}
		$cache_name = $econtroller . '-' . $emodel . $args . '.' . $type;
	 
		if (!isset ($tplSet[$cache_name])) {
			$tpl_name = $econtroller . '-' . $emodel . '-' . $type . '.php';
			$tplSet[$cache_name]['type'] = $type;
			$tplSet[$cache_name]['tpl_name'] = & $tpl_name;
			$tplSet[$cache_name]['cache_name'] = & $cache_name;
			$tplSet[$cache_name]['tpl_file'] = EMVC_PATH_ROOT . getCfg('themes_dir', 'themes') . DS . getCfg('theme', 'default') . DS . $tpl_name;
			$tplSet[$cache_name]['cpl_file'] = EMVC_PATH_ROOT . getCfg('cpl_dir', 'data') . DS . 'themes' . DS . getCfg('theme', 'default') . DS . $tpl_name;
			$tplSet[$cache_name]['cache_file'] = EMVC_PATH_ROOT . getCfg('cache_dir', 'cache') . DS . getCfg('theme', 'default') . DS . $cache_name;
		}
		if ($return === 'All') {
			return $tplSet[$cache_name];
		} else {
			if (isset ($tplSet[$cache_name][$return])) {
				return $tplSet[$cache_name][$return];
			} else {
				return false;
			}
		}
	}
	function getTplPathRelative(){
		return url_root().getCfg('themes_dir','themes').'/'.getCfg('theme','default').'/';
	}
}
?>
